package org.tnc.budget.webapp.util;

import java.io.File;
import java.util.Date;

import com.oreilly.servlet.multipart.FileRenamePolicy;

/**
 * 上传文件，存储为重命名后的文件，文件名为时间戳
 * 
 * @author houjj | 2011-4-4 下午01:53:54
 */
public class RandomFileRenamePolicy implements FileRenamePolicy {

	@Override
	public File rename(File file) {
		String body = "";
		String ext = "";
		int pot = file.getName().lastIndexOf(".");
		if (pot != -1) {
			body = (new Date()).getTime() + "";
			ext = file.getName().substring(pot);
		} else {
			body = (new Date()).getTime() + "";
			ext = "";
		}
		
		String newName = body + ext;
		file = new File(file.getParent(), newName);
		return file;
	}

}
